﻿<UserControl x:Class="DailyFx.Studio.MenuView"
             
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
             
             xmlns:controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
		     xmlns:behaviour="clr-namespace:MahApps.Metro.Behaviours;assembly=MahApps.Metro"	
             xmlns:UI="clr-namespace:DailyFx.UI;assembly=DailyFx.Api"
             xmlns:calib="clr-namespace:Caliburn.Micro;assembly=Caliburn.Micro"
             
             d:DesignHeight="25" d:DesignWidth="300">
    
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colours.xaml" />
                <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
                <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
                <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Blue.xaml" />
                <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml" />
            </ResourceDictionary.MergedDictionaries>
            <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
            <UI:MenuPartBindingConverter x:Key ="MenuPartBindingConverter"/>
        </ResourceDictionary>
    </UserControl.Resources>
    
    <Grid>
        <Menu Name="MainMenu" Width="Auto" Height="Auto" ItemsSource="{Binding Children}">
            <Menu.ItemContainerStyle>
                <Style BasedOn="{StaticResource {x:Type MenuItem}}"
                         TargetType="{x:Type MenuItem}" >
                    <Setter Property="Header" Value="{Binding Text}" />
                    <Setter Property="IsEnabled" Value="{Binding IsEnabled}" />
                    <Setter Property="calib:Message.Attach" Value="[Event Click] = [Action RunCommand()]" />
                    
                    <Setter Property="ItemsSource" 
                            Value="{Binding RelativeSource={RelativeSource Self}, Path=DataContext, 
                                            Converter={StaticResource MenuPartBindingConverter}, 
                                            ConverterParameter=IUIContainer&lt;IMenuPart&gt;.Children}" />
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding Path=IsDivider}" Value="True">
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate TargetType="{x:Type MenuItem}">
                                        <Separator Style="{DynamicResource {x:Static MenuItem.SeparatorStyleKey}}"/>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </Menu.ItemContainerStyle>
        </Menu>
    </Grid>
</UserControl>
